/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package researchgrants.parts.LoggedData;

import java.util.Date;

/**
 *
 * @author DOStudent1
 */
    public class LoggedLogableDate implements LoggedLogableObject{

        private String loggedString;
        private boolean isSet=false;

        LoggedLogableDate() {
        }


        public LoggedLogableObject fromLogableObject(LogableObject myDate) {
            LoggedLogableDate loggedMyDate=new LoggedLogableDate();
            if (myDate.isEmpty()) { 
                loggedMyDate.loggedString="";
                loggedMyDate.isSet=true;
            } else {
                Date date=((LogableDate)myDate).getDate();
                long time=date.getTime();
                loggedMyDate.loggedString=Long.toString(time);
                loggedMyDate.isSet=true;
            }
            return(loggedMyDate);
        }


        public LogableObject toLogableObject() {
            if (!isSet) {
                throw new RuntimeException("Not Initialized");
            }
            long time=Long.parseLong(loggedString);
            Date date=new Date();
            date.setTime(time);
            return(new LogableDate().fromDate(date));
        }

        public String toLoggedValue() {
            if (!isSet) {
                throw new RuntimeException("Not initialized");
            }
            return(loggedString);
        }

        public LoggedLogableObject fromLoggedValue(String loggedValue) {
            LoggedLogableDate loggedMyObject=new LoggedLogableDate();
            loggedMyObject.loggedString=loggedValue;
            loggedMyObject.isSet=true;
            return(loggedMyObject);
        }
    }
